<?php
class User extends AppModel {

     var $name = 'User';
     var $validate = array();
     
     function ValidateData(){
        $this->validate = array(
                                "Username"=>array(
                                                    "rule1" => array(
                                                                    "rule" => "notEmpty",
                                                                    "message" => "Username can not empty",
                                                                    ),
                                                    "rule2" => array(
                                                                    "rule" => array('minLength', 4),
                                                                    "message" => "Usernames must be at least 4 characters long",
                                                                    ),
                                                    "rule3" => array(
                                                                    "rule" => array('maxLength', 10),
                                                                    "message" => "Usernames must be no larger than 10 characters long",
                                                                    ),
                                                ),
                                "FirstName" => array(
                                                    "rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Please enter email !",
                                                                    ),
                                                  
                                                ),
                                "LastName" => array(
                                                    "rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Please enter website !",
                                                                    ),
                                                  
                                                ),
                            );
                            
       if($this->validates($this->validate)) 
        return TRUE; 
       else 
        return FALSE;  
    } 

    // Check exists username in database 
    function checkUsernameExisted(){
        if($this->data['Locum']['Username']){ 
            // Check exists username in database
            if($this->data['Locum']['id'])
                $user = $this->find('first',array('conditions'=>array('User.Username'=>$this->data['Locum']['Username'],'User.id !'=> $this->data['Locum']['id'])));
            else
                $user = $this->find('first',array('conditions'=>array('User.Username'=>$this->data['Locum']['Username'])));
            
            if(!empty($user))
                return true; // Already exist
            else 
                return false; // Not in the database
        }
        else{
            return false;
        }
    }
    
}
?>